package com.ricchieri.manage.bean;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.ricchieri.common.BusinessSettings;
import com.ricchieri.filter.UserFilter;
import com.ricchieri.model.Operation;
import com.ricchieri.util.FacesUtil;

@ManagedBean(name = "viewOperationMB")
@ViewScoped
public class ViewOperationManageBean extends CommonOperationManageBean {
	private static final long serialVersionUID = -5733730893955279433L;

	private Operation operation;
	private UserFilter userFilter;
	
	@PostConstruct
	public void init() {
		operation = (Operation) FacesUtil
				.getParametersFlash(BusinessSettings.KEY_OPEARATION);
		
		userFilter = (UserFilter) FacesUtil.getParametersFlash(BusinessSettings.KEY_FILTER);
		
		if(operation == null) {
			FacesUtil.redirectToNavigationCase(BusinessSettings.SEARCH_OPERATION);
		}
	}

	public Operation getOperation() {
		return operation;
	}

	public void setOperation(Operation operation) {
		this.operation = operation;
	}

	public String addOperation() {
		FacesUtil.addParametersFlash(BusinessSettings.KEY_USER,
				operation.getUser());

		return BusinessSettings.ADD;
	}
	
	public String doBacktToViewUserAccountStatus() {
		
		FacesUtil.addParametersFlash(BusinessSettings.KEY_USER,
				operation.getUser());
		return BusinessSettings.BACK;
	}
	
	public String doBackToSearchOperation(){
		FacesUtil.addParametersFlash(BusinessSettings.KEY_FILTER,
				userFilter);
		return BusinessSettings.SEARCH_OPERATION;
	}
}
